<!--模板html-->
<template>
  <div>
    <!-- 按钮 -->
    <div class="btns">
      <el-button type="warning" size="medium" plain  @click="toFormHandler">新增</el-button>
    </div>
    <!-- 表格 -->
    <div class="tab_content">
      <el-table :data="baseRole" stripe border style="width: 100%">
        <el-table-column align="center" prop="id" label="ID" width="600"></el-table-column>
        <el-table-column align="center"  prop="name"  label="姓名"  width="600"></el-table-column>
        <!-- //操作列 -->
        <el-table-column aligin:center width="600" align="center" label="操作">
          <template slot-scope="scope">
   
              <el-button-group>
                  <el-button type="primary" plain @click="editHandler(scope.row)" circle icon="el-icon-edit"></el-button>
                  <el-button type="primary" plain @click="deleteHandler(scope.row)" circle icon="el-icon-delete"></el-button>
              </el-button-group>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<!--脚本js-->
<script>
import { get, del } from '@/utils/request'
export default {
  // 定义变量，在模板中直接使用
  data() {
    return {
      baseRole:[],
      visible:false

    }

  },
  // 定义事件处理函数、方法
  methods:{
       // 删除数据
        deleteHandler(row){
            this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let url = "http://localhost:8888/baseRole/deleteById"
        del(url,{id:row.id}).then(resp =>{
          // 1. 提示
          this.$message({type:"success",message:resp.message});
          // 2. 刷新
          this.loadBaseRoles();
        })
      
      })
        },
        // 修改数据
        editHandler(row){
      this.$router.push({ 
        path:"/xiaoke/baseRole_form" ,
        query:row
      })
    },
    // 查询所有的基本文件数据
    loadBaseRoles(){
      let url = "http://localhost:8888/baseRole/query"
      get(url).then(resp=>{
        // 获取数据之后做的事情
        this.baseRole = resp.data;
        console.log(this.baseRole)
      })
    },
      // 跳转
        toFormHandler(){
      this.$router.push({ path:"/xiaoke/baseRole_form" })
    }

  },
  // 生命周期钩子函数
  created(){
    // this.basefiles
    this.loadBaseRoles()

  }
}
</script>

<!--样式html-->
<style lang="sass" scoped>

</style>
